import { useState, useEffect } from 'react';
import { Link } from "react-router-dom";
import taskService from '../../services/TaskService';
import { IFilter } from '@/typings/IFilter';

const HomePage = () => {
  const [name,setName] = useState<string>("");
  const [unfinishJobs,setUnfinishJobs] = useState<number>(0);
  useEffect(() => {
      let userName = localStorage.getItem("username")
      if (userName) {
          setName(userName)
      }
      let filter:IFilter = {
          completed:0,
          pageNum:1,
          pageSize:200
      }
      /** 查询未完成任务数，然后赋给unfinishJobs */
      taskService.query(filter).then((res:any)=>{
           if (res.data && res.data.items) {
            setUnfinishJobs(res.data.items.length)
           }
      })
  },[])
  return (
    <div className="home-welcome">
        <div>用户{name}登录系统，{new Date().toLocaleString()},</div>
        <div>您当前有{unfinishJobs}条未完成任务，
          <Link className="task-detail" to="/task">点击查看详情</Link>
        </div>
    </div>
  )
}

export default HomePage;